package com.shop.model.impl;

import java.util.List;

import com.shop.base.dao.ModelDao;
import com.shop.config.Config;
import com.shop.driver.MySql;

/**
 * ORM 数据模型
 */
public class Model implements ModelDao{
	// 驱动对象
	private static MySql mySql;

	// 表名
	protected String tableName;

	// 表前缀
	protected String tableNamePerfix;
	
	//数据库连接池
	protected MySql [] link ;
	
	protected List<?> dataBaseConfig;
	
	protected String $configPath = "/config/jdbc.properties";
	
	
	//数据库配置
	
	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getTableNamePerfix() {
		return tableNamePerfix;
	}

	public void setTableNamePerfix(String tableNamePerfix) {
		this.tableNamePerfix = tableNamePerfix;
	}
	
	public Model (String tabName, String dbPerfix) {
		
		if (tabName == null) {
			
			String className = this.getClass().getName();
			
			tabName = className.substring(0, className.lastIndexOf("Bean"));;
		}
		
		mySql = MySql.getInitance(this.$configPath);
		this.tableName = tabName;
		
		this.tableNamePerfix = dbPerfix;
		
		//初始化
		this.init();
		
	}

	/**
	 * 获取当前数据表字段 
	 */
	public List<?> getField() {
		return mySql.getField(this.tableName, (String)Config.getKey("jdbc.dbName"));
	}
	
	
	@Override
	public void init () {
		
	}
	
	public static MySql getMySql() {
		return mySql;
	}

	public static void setMySql(MySql mySql) {
		Model.mySql = mySql;
	}
	
	
}
